<?php
class class_Base {
	function __construct() {
		require('conexion.php');

		$this->link1 = mysql_connect("$servidor", "$usuario", "$password");
		mysql_select_db("$base", $this->link1);
		mysql_query("SET NAMES 'utf8'", $this->link1);
	}

	protected function getObjectArray($query){
		$q = mysql_query($query);
		while ($r = mysql_fetch_object($q)) {
			$objs[] = $r;
		}
		return $objs;
	}

	protected function getObject($query){
		$q = mysql_query($query);
		if ($r = mysql_fetch_object($q)){
			$obj[] = $r;
		}
		return $obj;
	}

	protected function execute($query){
		if (mysql_query($query)){
			return true;
		}
		if (mysql_error()){
			throw  new Exception("Error al ejecutar la sentencia Sql");
		}
		return false;
	}

	protected function getCondition($critery, $initial){
		$condition = null;
		if ($critery){
			$condition = (($initial)? " where ": " and ").$critery;
		}

		return $condition;
	}
	
	protected function exitsValueField($table, $field, $value){
		$query = "select ".$field." from ".$table. " where ".$field . " = ". $value;
		$obj = $this->getObject($query);
		return ($obj);
	}
}
?>
